OBJ=$(patsubst %.c, %.o, $(wildcard ./*.c))
TARGET=add_main

LDFLAGS=-L./src_so -L./src_a
LIBS=-lMyAdd -lMyDiv

SO_DIR=./src_so
A_DIR=./src_a

PATHS=/tmp/demoMain/
BIN=/usr/local/bin/

#变量取值用$()
$(TARGET):$(OBJ)
	$(CC) $^ $(LIBS) $(LDFLAGS) -o $@

#模式匹配  %目标：%依赖
%.o:%.c
	$(CC) -c $^ -o $@

all:
	make -C $(SO_DIR)
	make -C $(A_DIR)

install:$(TARGET)
	if [ -d $(PATHS) ];            \
		then echo $(PATHS) exist;  \
	else                           \
		mkdir $(PATHS);            \
		cp $(TARGET) $(PATHS);     \
		sudo ln -sv $(PATHS)$(TARGET) $(BIN);    \
	fi


#伪目标
.PHONY:clean install

clean:
	$(RM) *.o $(TARGET)

show:
	echo $(CC)
	echo $(CXX)
	echo $(RM)
	echo $(wildcard ./*.c)
	echo $(patsubst %.c, %.o, $(wildcard ./*.c))
